package write

import "time"

var PackageName = "message/write"

type Message struct {
	Id              string     `sqlx:"id,primaryKey" validate:"required"`
	Archived        *int       `sqlx:"archived" json:",omitempty"`
	ConversationID  string     `sqlx:"conversation_id" validate:"required"`
	TurnID          *string    `sqlx:"turn_id" json:",omitempty"`
	Sequence        *int       `sqlx:"sequence" json:",omitempty"`
	CreatedAt       *time.Time `sqlx:"created_at" json:",omitempty"`
	UpdatedAt       *time.Time `sqlx:"updated_at" json:",omitempty"`
	CreatedByUserID *string    `sqlx:"created_by_user_id" json:",omitempty"`
	Mode            string     `sqlx:"mode" json:",omitempty"`
	Role            string     `sqlx:"role" validate:"required"`
	Status          string     `sqlx:"status" `
	Type            string     `sqlx:"type" validate:"required"`
	Content         string     `sqlx:"content"`
	// Summary holds a compact retained summary for this message.
	Summary        *string `sqlx:"summary" json:",omitempty"`
	ContextSummary *string `sqlx:"context_summary" json:",omitempty"`
	// EmbeddingIndex stores a serialized vector index used for semantic match.
	EmbeddingIndex       *[]byte `sqlx:"embedding_index" json:",omitempty"`
	Tags                 *string `sqlx:"tags" json:",omitempty"`
	Interim              *int    `sqlx:"interim" json:",omitempty"`
	ElicitationID        *string `sqlx:"elicitation_id" json:",omitempty"`
	ParentMessageID      *string `sqlx:"parent_message_id" json:",omitempty"`
	SupersededBy         *string `sqlx:"superseded_by" json:",omitempty"`
	LinkedConversationID *string `sqlx:"linked_conversation_id" json:",omitempty"`
	ToolName             *string `sqlx:"tool_name" json:",omitempty"`
	// AttachmentPayloadID links a message to an uploaded/staged attachment payload.
	AttachmentPayloadID *string `sqlx:"attachment_payload_id" json:",omitempty"`
	// ElicitationPayloadID links a message to an elicitation response payload.
	ElicitationPayloadID *string     `sqlx:"elicitation_payload_id" json:",omitempty"`
	Has                  *MessageHas `setMarker:"true" format:"-" sqlx:"-" diff:"-" json:"-"`
}

type MessageHas struct {
	Id                   bool
	Archived             bool
	ConversationID       bool
	TurnID               bool
	Sequence             bool
	CreatedAt            bool
	UpdatedAt            bool
	CreatedByUserID      bool
	Mode                 bool
	Role                 bool
	Status               bool
	Type                 bool
	Content              bool
	Summary              bool
	ContextSummary       bool
	EmbeddingIndex       bool
	Tags                 bool
	Interim              bool
	ElicitationID        bool
	ParentMessageID      bool
	SupersededBy         bool
	LinkedConversationID bool
	ToolName             bool
	AttachmentPayloadID  bool
	ElicitationPayloadID bool
}

func (m *Message) ensureHas() {
	if m.Has == nil {
		m.Has = &MessageHas{}
	}
}
func (m *Message) SetId(v string)    { m.Id = v; m.ensureHas(); m.Has.Id = true }
func (m *Message) SetArchived(v int) { m.Archived = &v; m.ensureHas(); m.Has.Archived = true }
func (m *Message) SetConversationID(v string) {
	m.ConversationID = v
	m.ensureHas()
	m.Has.ConversationID = true
}
func (m *Message) SetTurnID(v string)       { m.TurnID = &v; m.ensureHas(); m.Has.TurnID = true }
func (m *Message) SetSequence(v int)        { m.Sequence = &v; m.ensureHas(); m.Has.Sequence = true }
func (m *Message) SetCreatedAt(v time.Time) { m.CreatedAt = &v; m.ensureHas(); m.Has.CreatedAt = true }
func (m *Message) SetUpdatedAt(v time.Time) { m.UpdatedAt = &v; m.ensureHas(); m.Has.UpdatedAt = true }
func (m *Message) SetCreatedByUserID(v string) {
	m.CreatedByUserID = &v
	m.ensureHas()
	m.Has.CreatedByUserID = true
}
func (m *Message) SetMode(v string)    { m.Mode = v; m.ensureHas(); m.Has.Mode = true }
func (m *Message) SetRole(v string)    { m.Role = v; m.ensureHas(); m.Has.Role = true }
func (m *Message) SetStatus(v string)  { m.Status = v; m.ensureHas(); m.Has.Status = true }
func (m *Message) SetType(v string)    { m.Type = v; m.ensureHas(); m.Has.Type = true }
func (m *Message) SetContent(v string) { m.Content = v; m.ensureHas(); m.Has.Content = true }
func (m *Message) SetSummary(v string) { m.Summary = &v; m.ensureHas(); m.Has.Summary = true }
func (m *Message) SetEmbeddingIndex(v []byte) {
	m.EmbeddingIndex = &v
	m.ensureHas()
	m.Has.EmbeddingIndex = true
}
func (m *Message) SetToolName(v string) { m.ToolName = &v; m.ensureHas(); m.Has.ToolName = true }
func (m *Message) SetInterim(v int)     { m.Interim = &v; m.ensureHas(); m.Has.Interim = true }
func (m *Message) SetLinkedConversationID(v string) {
	m.LinkedConversationID = &v
	m.ensureHas()
	m.Has.LinkedConversationID = true
}
func (m *Message) SetAttachmentPayloadID(v string) {
	m.AttachmentPayloadID = &v
	m.ensureHas()
	m.Has.AttachmentPayloadID = true
}
func (m *Message) SetElicitationPayloadID(v string) {
	m.ElicitationPayloadID = &v
	m.ensureHas()
	m.Has.ElicitationPayloadID = true
}
func (m *Message) SetParentMessageID(v string) {
	m.ParentMessageID = &v
	m.ensureHas()
	m.Has.ParentMessageID = true
}

func (m *Message) SetElicitationID(id string) {
	m.ElicitationID = &id
	m.ensureHas()
	m.Has.ElicitationID = true
}
